<!-- 批量设置单位服务商 -->
<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="500px"
    append-to-body
    :close-on-click-modal="false"
    @close="closeModal"
  >
    <SelectFacilitator
      :defaultValue.sync="serviceCompanyItems"
      :companyType="1"
    />
    <div class="mt-15 color9 mx-20">为单位指定服务商后，单位可开具服务商上架的项目。</div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import SelectFacilitator from "@/views/facilitator/facilitator/selectFacilitator";
import { batchSetCompany } from '@/api/company/company';

export default {
  components: {
    SelectFacilitator,
  },
  data() {
    return {
      title: "批量设置单位服务商",
      open: false,
      form: {
        batchSetType: 0, // 设置类型：0批量设置服务商 1批量设置跟进人 2批量设置审核机构
        companyIds: "", // 勾选则单位ids
        serviceCompanyIds: "",
      },
      serviceCompanyItems: [],
    };
  },
  methods: {
    openModal(ids) {
      this.open = true;
      this.form.companyIds = ids;
    },
    closeModal() {
      Object.assign(this.$data, this.$options.data()); // 存在自定义校验规则不能重置data
    },
    submitForm() {
      const that = this;
      that.form.serviceCompanyIds = that.serviceCompanyItems.map(v=> v.id).join(',');
      batchSetCompany(that.form).then(res=>{
        that.$message.success("批量设置成功");
        that.$emit("refresh");
        that.closeModal();
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
